package com.hwl.lab.service;

import com.hwl.lab.entity.Role;
import com.hwl.lab.entity.User;
import com.hwl.lab.repository.RoleRepository;
import com.hwl.lab.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleService {
    @Autowired
    private RoleRepository roleRepository;
    //分页实现
    public Page<Role> findAll( Integer page, Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return roleRepository.findAll(pageable);
    }
    //不分页
    public List<Role> findAll() {
        return roleRepository.findAll();
    }
    //通过账号查询
    public Role findByRoleid(String roleid){
        return roleRepository.findByRoleid(roleid);
    }
    //保存，修改
    public Role saveRole(Role role){
       return  roleRepository.save(role);
    }
    //通过账号删除
    public void deleteById(Long id){
        roleRepository.deleteById(id);
    }
}
